package com.inspur.controller;

import com.inspur.pojo.CertificateInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 证书Controller
 */
@Controller
@RequestMapping("/cer")
public class CertificateController {

    private static  final Logger LOGGER = LoggerFactory.getLogger(CertificateController.class);

    @RequestMapping("/toCertificateList")
    public String certificateList(HttpServletRequest request, HttpSession session){
        request.setAttribute("request","requestValue");
        request.getSession().setAttribute("requestSession","requestSessionValue");
        session.setAttribute("session","sessionValue");
        return "certificateList";
    }

    @RequestMapping("/toCertificateAdd")
    public String toCertificateAdd(HttpServletRequest request, HttpSession session){
        request.setAttribute("request","requestValue");
        request.getSession().setAttribute("requestSession","requestSessionValue");
        session.setAttribute("session","sessionValue");
        return "certificateAdd";
    }
    @RequestMapping("/addCertificate")
    public String addCertificate(CertificateInfo certificateInfo,String certificateTime) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("enter CertificateController.addCertificate,certificateInfo:{},certificateTime:{}", certificateInfo, certificateTime);
        }
        return "login";
    }



    /**
     * form表单提交 Date类型数据绑定
     * <功能详细描述>
     * @param binder
     * @see [类、类#方法、类#成员]
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

    }
}
